﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebSite.Models
{
    using Ruandao.MiniFace;

    public class ArticleContentWidget : WidgetBase
    {
        public string Title { get; set; }
        public string Content { get; set; }
        public string Details { get; set; }

        public ArticleContentWidget()
        {
            Title = "默认的标题";
            Content = "缺省的内容";
            Details = "Details Default string。。。。";
        }

        public override void Render( TemplateContext templateContext, System.IO.TextWriter writer)
        {
            SetProperties();

            templateContext.PythonScope.SetVariable("Title", this.Title);
            templateContext.PythonScope.SetVariable("Content", this.Content);
            templateContext.PythonScope.SetVariable("Details", this.Details);

            foreach (var content in this.WidgetTemplate.Contents)
            {
                content.Render(templateContext, writer);
            }

            templateContext.PythonScope.RemoveVariable("Title"); 
            templateContext.PythonScope.RemoveVariable("Content"); 
            templateContext.PythonScope.RemoveVariable("Details"); 
        }

        private void SetProperties()
        {
            if ( Properties.ContainsKey("Title") )    this.Title = Properties["Title"];
            if ( Properties.ContainsKey("Content") )  this.Content = Properties["Content"];
            if ( Properties.ContainsKey("Details") )  this.Details = Properties["Details"];
        }
    }
}